import { createStore } from 'vuex'

import VuexPersistence from 'vuex-persist'

import API from "@/api/tdtApi"
import TQ from '@/api/tianqi';
const vuexLocal = new VuexPersistence({
  storage: window.localStorage
})

export default createStore({
  state: {
    data:[],
    exp:0,
	tiandituConfig:{
		lxFlag:false,
		
	},
	lists:[],
	tianqi:{},
	workerUser:[]
  },
  getters: {
  },
  mutations: {
    setData(state,res){
      state.data=res
    },
    setExp(state,val){
      state.exp=val
    },
	setTianDiTuConfig(state,obj){
		state.tiandituConfig = obj
	},
	setLists(state,arr){
		state.lists=arr
	},
	setTianqi(state,obj){
		state.tianqi = obj
	},
	setWorkerUser(state,obj){
		
		state.workerUser = obj
		
	}

  },
  actions: {
    getApi({commit}){
      return new Promise((resolve, reject) => {
        commit("setExp",new Date().getTime()+50000)
        let res = [1,2,3,4,5,6]
        commit("setData",res)
        resolve(res)
      })
      
    },
	setTdtConfig({commit},obj){
		
		commit("setTianDiTuConfig",obj)
	},
	getTdtLx({commit}){
		API.getTdtApiLx().then(e=>{
			console.log(e.data.lists,49)
			commit("setLists",e.data.lists)
		})
		setInterval(()=>{
			API.getTdtApiLx().then(e=>{
				console.log(e.data.lists,49)
				commit("setLists",e.data.lists)
			})
		},3000)
		
	},
	getTianQiFun({commit}){
		return TQ.getTianQi().then(e=>{
			console.log(e,68)
			commit("setTianqi",e)
		})
	},
	heart({commit},obj){
		// console.log(obj,76)
	},
	studentstats({commit},obj){
		console.log(obj,79)
	},
	jiekou1({commit,state},obj){
		// let arr = state.arr
		// arr.push(1)
		// commit("setArr",arr)
		console.log("jiekou1",obj)
	},
	jiekou2({commit},data){
		console.log("jiekou2",data)
	},
	threeYearPerson({commit},data){
		console.log('threeYearPerson',data)
	},
	workerOnline({commit},data){
		console.log('workerOnline',data)
	},
	workerUser({commit},data){
		console.log('workerUser',data)
		commit("setWorkerUser",data)
	},
	workerCity({commit},data){
		console.log('workerCity',data)
	}
	
  },
  modules: {
  },
  plugins: [vuexLocal.plugin]
})
